﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.Membership.OpenAuth;
using System.Data;
using System.Data.SqlClient;

namespace Groep8.Admin
{
    /// <summary>
    /// Deze klasse regelt alle admin functies.
    /// </summary>
    public partial class Admin : Page
    {
        DataTable dsFestival;
        public string Message = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["action"] == "created")
                Message = "User created!";
            else if (Request.QueryString["action"] == "delete")
            {
                Membership.DeleteUser(Request.QueryString["id"], true);
                Message = "User " + Request.QueryString["id"] + "deleted!";
            }
            RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];

            DataAccessLayer db = new DataAccessLayer();
            dsFestival = db.Select("SelectUsers");
        }

        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            Roles.AddUserToRole(RegisterUser.UserName, "Guest");

            string continueUrl = RegisterUser.ContinueDestinationPageUrl;
            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect("~/Admin/Admin.aspx?action=created");
        }
    }
}